package com.ruoyi.web.controller.djb;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.djb.domain.DjbVersion;
import com.ruoyi.djb.service.IDjbVersionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 版本管理Controller
 * 
 * @author xxd
 * @date 2023-12-08
 */
@Controller
@RequestMapping("/djb/version")
public class DjbVersionController extends BaseController
{
    private String prefix = "djb/version";

    @Autowired
    private IDjbVersionService djbVersionService;

    @RequiresPermissions("djb:version:view")
    @GetMapping()
    public String version()
    {
        return prefix + "/version";
    }

    /**
     * 查询版本管理列表
     */
    @RequiresPermissions("djb:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbVersion djbVersion)
    {
        startPage();
        List<DjbVersion> list = djbVersionService.selectDjbVersionList(djbVersion);
        return getDataTable(list);
    }

    /**
     * 导出版本管理列表
     */
    @RequiresPermissions("djb:version:export")
    @Log(title = "版本管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbVersion djbVersion)
    {
        List<DjbVersion> list = djbVersionService.selectDjbVersionList(djbVersion);
        ExcelUtil<DjbVersion> util = new ExcelUtil<DjbVersion>(DjbVersion.class);
        return util.exportExcel(list, "版本管理数据");
    }

    /**
     * 新增版本管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存版本管理
     */
    @RequiresPermissions("djb:version:add")
    @Log(title = "版本管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbVersion djbVersion)
    {
        return toAjax(djbVersionService.insertDjbVersion(djbVersion));
    }

    /**
     * 修改版本管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbVersion djbVersion = djbVersionService.selectDjbVersionById(id);
        mmap.put("djbVersion", djbVersion);
        return prefix + "/edit";
    }

    /**
     * 修改保存版本管理
     */
    @RequiresPermissions("djb:version:edit")
    @Log(title = "版本管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbVersion djbVersion)
    {
        return toAjax(djbVersionService.updateDjbVersion(djbVersion));
    }

    /**
     * 删除版本管理
     */
    @RequiresPermissions("djb:version:remove")
    @Log(title = "版本管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbVersionService.deleteDjbVersionByIds(ids));
    }
}
